package com.hankol.newretail

import android.os.Bundle
import android.content.Intent
import android.view.View
import androidx.lifecycle.Observer
import com.alibaba.android.arouter.facade.annotation.Route
import com.baselibrary.Constants
import com.baselibrary.MessageBus
import com.baselibrary.manager.LoadingManager
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.*
import com.baselibrary.activity.BaseActivity
import com.baselibrary.adapter.OrderBottomItemAdapter
import com.baselibrary.bean.OrderBottomItemBean
import com.baselibrary.bean.ReceiveAddressBean
import com.baselibrary.extension.*
import com.baselibrary.manager.DialogManager
import com.hankol.newretail.adapter.OrderGoodListAdapter
import com.hankol.newretail.bean.*
import com.hankol.newretail.databinding.ActivityOrderDetailNewRetailBinding
import com.hankol.newretail.utils.RetailPopUtils
import com.hankol.newretail.viewmodel.OrderAboutViewModel
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode

/**订单详情
 * @author: merbng
 * @time: 2022/8/10 14:16
 * @description:
 */
@Route(path = ActivityRouter.NEW_RETAIL.ORDER_DETAIL)
class OrderDetailNewRetailActivity : BaseActivity(), View.OnClickListener {
    private val mAdapter by lazy { OrderGoodListAdapter() }
    private val mBottomAdapter by lazy { OrderBottomItemAdapter(emptyList()) }
    private val mTotalMoneyFreightAdapter by lazy { OrderBottomItemAdapter(emptyList()) }

    private lateinit var viewModel: OrderAboutViewModel
    private lateinit var binding: ActivityOrderDetailNewRetailBinding
    var orderId: String = ""
    var mDataBean: OrderLoadDetailBean? = null
    override fun getLayoutId(): Int {
        initImmersion(true)
        return R.layout.activity_order_detail_new_retail
    }

    override fun init() {
        setStatusBarHeight(R.color.color_F9F9F9)
        StatusBarUtil.setStatusBarDarkTheme(this, true)
        if (!EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().register(this)
        }
        LoadingManager.showProgress(this, "加载中...")
        binding = getDataBinding()
        viewModel = getActivityViewModelProvider(this).get(OrderAboutViewModel::class.java)
        initData()
    }

    private fun initData() {
        if (ARouterUtils.parseParams(intent.extras!!, Constants.KEY_ORDER_ID)[0].checkNotNull()) {
            orderId = ARouterUtils.parseParams(intent.extras!!, Constants.KEY_ORDER_ID)[0]
        }
        initView()
        initListener()
        initObserver()

    }

    override fun onNewIntent(intent: Intent?) {
        super.onNewIntent(intent)
        if (intent.checkNotNull()) {
            if (ARouterUtils.parseParams(intent?.extras!!, Constants.KEY_ORDER_ID)[0].checkNotNull()) {
                orderId = ARouterUtils.parseParams(intent.extras!!, Constants.KEY_ORDER_ID)[0]
            }

        }
    }

    private fun reqData() {
        viewModel.requestOrderDetail(orderId)
    }

    private fun initListener() {
        binding.backImageView.setOnClickListener(this)
        binding.ivCustomerService.setOnClickListener(this)
        binding.imgEditChangeAddress.setOnClickListener(this)
        binding.rlLogistics.setOnClickListener(this)
        binding.tvCancelOrder.setOnClickListener(this)
        binding.tvPay.setOnClickListener(this)
        binding.tvSeeLogistics.setOnClickListener(this)
        binding.tvConfirmReceive.setOnClickListener(this)
        binding.tvDeleteOrder.setOnClickListener(this)
        binding.tvWineryName.setOnClickListener(this)
        mAdapter.setOnItemClickListener { adapter, view, position ->
            //跳转 商品详情
            val mallOrderSkuDtoBean = adapter.data[position] as MallOrderSkuDtoBean
            if (!DoubleClickHelper.isOnDoubleClick()) {
                val hashMap = java.util.HashMap<String, Any>()
                hashMap[Constants.GOODS_DETAIL_ID] = mallOrderSkuDtoBean.spuId
                hashMap[Constants.GOODS_SKU_ID] = mallOrderSkuDtoBean.skuId
                hashMap[Constants.GOODS_DETAIL_SOURCE] = "订单详情"
                ARouterUtils.jump(ActivityRouter.NEW_RETAIL.GOODS_DETAUILS, hashMap)
            }
        }
        mAdapter.setOnItemChildClickListener { adapter, view, position ->
            val mallOrderSkuDtoBean = adapter.data[position] as MallOrderSkuDtoBean
            when (view.id) {
                R.id.tv_apply_after -> {
                    //售后
                    if (mallOrderSkuDtoBean.afterSale.checkNotNull()) {
                        //售后详情
                        val hasMap: HashMap<String, Any> = hashMapOf()
                        mallOrderSkuDtoBean.afterSale?.let {
                            hasMap[AfterSalesDetailsActivity.AFTER_SALES_ID] = it.id
                            ARouterUtils.jump(ActivityRouter.NEW_RETAIL.AFTER_SALES_DETAILS, hasMap)
                        }
                    } else {
                        if (!DoubleClickHelper.isOnDoubleClick()) {
                            //申请售后
                            val bundle = Bundle()
                            bundle.putParcelable(Constants.KEY_APPLY_AFTER_DTO_INFO_BEAN, mallOrderSkuDtoBean)
                            ARouterUtils.jump(ActivityRouter.NEW_RETAIL.AFTER_SALES_APPLY, bundle)
                        }
                    }
                }
            }
        }
    }

    private fun initObserver() {
        viewModel.orderLoadDetailLD.observe(this, Observer {
            if (it.checkNotNull()) {
                detailInfohandle(it)
            } else {
                LoadingManager.hideProgress(this)
                finish()
            }
        })
        //取消订单 弹窗 理由列表
        viewModel.cancelOrderReasonLD.observe(this, Observer {
            cancelOrderHandle(it)
        })
        //取消订单 确认
        viewModel.cancelOrderLD.observe(this, Observer {
            "订单取消成功".toast()
            EventBusUtils.sendNotify(MessageBus.msgId_order_cancel_success)
            reqData()
        })
        //快递信息
        viewModel.logisticsInfoLD.observe(this, Observer {
            if (it.checkNotNull() && it.kuaiDiInfos.size > 0) {
                binding.rlLogistics.visibility = View.VISIBLE
                binding.tvSeeLogistics.visibility = View.VISIBLE
                showLogisticsInfo(it)
            } else {
                binding.rlLogistics.visibility = View.GONE
                binding.tvSeeLogistics.visibility = View.GONE
            }
        })
        //修改地址
        viewModel.changeAddressLD.observe(this, Observer {
            LoadingManager.hideProgress(this)
            if (it) {
                "修改成功".toast()
                if (mDataBean?.status == 1) {
                    mDataBean?.isAllowModifyAddress = 0//修改完 不可修改
                    binding.imgEditChangeAddress.isSelected = false
                }
            }
        })
        //订单超时刷新
        viewModel.overTimeCancelLD.observe(this, Observer {
            reqData()
        })

        //确认收货
        viewModel.confirmReciveLD.observe(this, Observer {
                LoadingManager.hideProgress(this)
//                CommonBusiness.shareSuccess(this, 14, "收货成功")
            if (it.rewardScore>0) {
                DialogManager.showCoinDialog(this, "收货成功", it.rewardScore)
            }
                EventBusUtils.sendNotify1Value(MessageBus.msgId_confirm_receive_success, orderId)
                //刷新
                reqData()
        })
        //删除订单
        viewModel.delOrderLD.observe(this, Observer {
            LoadingManager.hideProgress(this)
            if (it == null) return@Observer
            if (it) {
                HKToastUtils.showToast("删除成功")
                EventBusUtils.sendNotify1Value(MessageBus.msgId_del_order, orderId)
                finish()
            } else {
                HKToastUtils.showToast("删除失败")
            }
        })
        //七天自动确认收货
        viewModel.overTimeReceiveLD.observe(this, Observer {
            if (it.checkNotNull() && it.success) {
                reqData()
            }
        })

        //纯酒币（无现金）_电商订单_生成支付订单
        viewModel.onlyScoreOrderLD.observe(this, Observer {
            EventBusUtils.sendNotify(MessageBus.msgId_pay_success)
            val hashMap = java.util.HashMap<String, Any>()
            hashMap[PaySuccessActivity.KEY_POIDS] = it.poids.checkValue()
            hashMap[PaySuccessActivity.KEY_PAY_PRICE_SUM] = "${it.payPriceSum}"
            hashMap[PaySuccessActivity.KEY_SCORE_DEDUCTPRICE_SUM] = "${it.scoreDeductPriceSum}"
            hashMap[PaySuccessActivity.KEY_SHOULD_REWARD_SCORE] = "${it.shouldRewardScore}"
            ARouterUtils.jump(ActivityRouter.NEW_RETAIL.PAY_SUCCESS, hashMap)
            AppManager.getAppManager().finishActivity()
        })
    }

    //物流信息
    private fun showLogisticsInfo(bean: LogisticeInfoBean) {
        if (bean.wuliu.checkNotNull()) {
            if (bean.wuliu[0].data.checkNotNull()) {
                val data = bean.wuliu[0].data[0]
                data.let {
                    binding.tvPostStatus.text = "${OptionUtils.kuaidiStatus(it.status.checkValue())}"
                    binding.tvPostTime.text = "${it.time.checkValue()}"
                    binding.tvPostDetail.text = "${it.context.checkValue()}"
                    OptionUtils.kuaidiStatusIcon(binding.ivPostStatus, it.status.checkValue(), true)
                }
            }
        }
    }

    val orderBottomList = mutableListOf<OrderBottomItemBean>()
    private fun detailInfohandle(detailBean: OrderLoadDetailBean) {
        detailBean?.let {
            mDataBean = it
            //地址信息
            setAddressInfo(it.express.userAddressName.checkValue(), it.express.userAddressPhone.checkValue(), it.express.userAddressAddress.checkValue())
            //酒窖名称
            binding.tvWineryName.text = it.shopDto[0].mallOrderSkuDtoList[0].shopName.checkValue()
            binding.tvPostStyle.text = OptionUtils.postStyle(it.postOption)
            mAdapter.setOrderStatus(it.status)
            mAdapter.setNewData(it.shopDto[0].mallOrderSkuDtoList)
            //商品总额 酒币抵扣 运费
            val totalMoneyFreightList = mutableListOf<OrderBottomItemBean>()
            totalMoneyFreightList.add(OrderBottomItemBean("商品总额", "¥${AmountUtil.changeF2YKeepTwo("${it.price}")}", Constants.TYPE_TXT))
            if (it.scoreDeductPrice != 0) {
                totalMoneyFreightList.add(OrderBottomItemBean("酒币抵扣", "-¥${AmountUtil.changeF2YKeepTwo("${it.scoreDeductPrice}")}", Constants.TYPE_TXT))
            }
            totalMoneyFreightList.add(OrderBottomItemBean("运费", "¥${AmountUtil.changeF2YKeepTwo("${it.postagePrice}")}", Constants.TYPE_TXT))
            mTotalMoneyFreightAdapter.setNewData(totalMoneyFreightList)

            orderBottomList.clear()
            orderBottomList.add(OrderBottomItemBean("订单编号", it.code.checkValue(), Constants.TYPE_HAVE_BUTTON))
            orderBottomList.add(OrderBottomItemBean("下单时间", TimeUtil.setYearMonthDay(it.ctime), Constants.TYPE_TXT))
            //状态：0-待付款（创建），1-待发货（已付款），2-待收货（已发货），3-待评价（已收货），5-已完成，6-已关闭
            binding.tvTopStatus.text = OptionUtils.getOrderStatusString(it.status)
            binding.tvTopTip.text = OptionUtils.getOrderDetailTopTip(it.status)
            binding.tvShouldRealPrice.text = "${OptionUtils.showShouldRealPay(it.status)}"
            //底部按钮 初始化
            binding.llBottom.visibility = View.GONE
            binding.tvDeleteOrder.visibility = View.GONE
            binding.tvCancelOrder.visibility = View.GONE
            binding.tvPay.visibility = View.GONE
            binding.tvConfirmReceive.visibility = View.GONE
            binding.tvSeeLogistics.visibility = View.GONE
            binding.countdownView4Recive.visibility = View.GONE

            when (it.status) {
                0 -> {//待付款
                    waitPayHandle()
                }
                1 -> {
                    //待发货
                    waitSendHandle()
                }
                2 -> {//待收货
                    waitReceiveHandle()
                }
                5 -> {//已完成
                    completeHandle()
                }
                6 -> {//已关闭
                    closeHandle()
                }
            }
            if (it.desc.checkNotNull()) {
                orderBottomList.add(OrderBottomItemBean("订单备注", it.desc.checkValue(), Constants.TYPE_TXT))
            }
            mBottomAdapter.setNewData(orderBottomList)
            //0 6 应付金额    else  实付金额
            binding.tvRealPrice.text = "${AmountUtil.changeF2YKeepTwo("${if (it.status == 0 || it.status == 6) it.shouldPayPrice else it.payPrice}")}"
            binding.tvRealPrice.setMallPriceTTF(this)

        }
        binding.rlTopTitle.postDelayed(Runnable { LoadingManager.hideProgress(this) }, 500)

    }

    private fun initView() {
        binding.rvOrderGoods.adapter = mAdapter
        binding.rvTotalMoneyCoinFreight.adapter = mTotalMoneyFreightAdapter
        binding.rvOrderBottom.adapter = mBottomAdapter
        binding.tvUnit.setMallPriceTTF(this)
    }

    override fun onClick(v: View) {
        when (v.id) {
            R.id.backImageView -> {
                finish()
            }
            R.id.tv_winery_name -> {
                //酒窖详情
                if (!DoubleClickHelper.isOnDoubleClick()) {
                    mDataBean?.let {
                        val hashMap = java.util.HashMap<String, Any>()
                        hashMap["id"] = "${it.shopDto[0].wineryId}"
                        hashMap["dealerCode"] = "${it.shopDto[0].dealerCode}"
                        ARouterUtils.jump(ActivityRouter.WINE_CELLAR.WINCE_CELLAR_DETAIL, hashMap)
                    }
                }
            }
            R.id.iv_customer_service -> {
                if (!DoubleClickHelper.isOnDoubleClick()) {
                    ARouterUtils.jump(ActivityRouter.MINE_CENTER.CUSTOMER_SERVICE, this)
                }
            }
            R.id.img_edit_change_address -> {
                if (!DoubleClickHelper.isOnDoubleClick()) {
                    if (mDataBean?.status == 1 && mDataBean?.isAllowModifyAddress == 1) {//1-待发货（已付款）
                        //待发货
                        //弹窗提示 只能修改一次【避免影响物流时效 只能修改一次】
                        PopUtils.showOkCancelDialog(this, "避免影响物流时效\n只能修改一次", object : PopUtils.ICallBack {
                            override fun clickOk() {
                                openChangeAddress()
                            }

                            override fun clickCancel() {}
                        }, false, "确认修改", "取消", true)
                        return
                    } else if (mDataBean?.status == 0) {//0-待付款（创建）
                        openChangeAddress()
                    } else {
                        "您已修改过地址".toast()
                    }
                }
            }
            R.id.tv_cancel_order -> {
                if (!DoubleClickHelper.isOnDoubleClick()) {
                    //取消订单 -- 弹窗
                    viewModel.reqCancelOrderReasonList()
                }
            }
            R.id.tv_pay -> {
                if (!DoubleClickHelper.isOnDoubleClick()) {
                    //付款
                    mDataBean?.let {
                        if (it.shouldPayPrice > 0) {
                            val hashMap = java.util.HashMap<String, Any>()
                            hashMap[SelectPayWayActivity.KEY_POIDS] = "[${it?.poId}]"
                            hashMap[SelectPayWayActivity.KEY_OVERTIME] = "${it?.overtime}"
                            hashMap[SelectPayWayActivity.KEY_SHOULD_PAY_PRICE] = "${it?.shouldPayPrice}"
                            ARouterUtils.jump(ActivityRouter.NEW_RETAIL.SELECT_PAY_WAY, hashMap)
                        } else {
                            //直接纯酒币支付
                            onlyCoinPay("[${it.poId}]")
                        }
                    }
                }
            }
            R.id.tv_confirm_receive -> {
                if (!DoubleClickHelper.isOnDoubleClick()) {
                    //确认收货   预处理
                    if (mDataBean?.receiveOvertime == 0L) {
                        //有正在处理的售后单
                        PopUtils.showOkCancelDialog(this, "订单存在售后\n继续${if (mDataBean?.postOption == 0) "收" else "提"}货，将撤销售后申请", object : PopUtils.ICallBack {
                            override fun clickOk() {
                                //强制确认收货
                                //确定
                                LoadingManager.showProgress(this@OrderDetailNewRetailActivity, "请稍后...")
                                viewModel.requestConfirmRecive(orderId)
                            }

                            override fun clickCancel() {
                            }
                        })
                        LoadingManager.hideProgress(this)
                    } else {
                        PopUtils.showOkCancelDialog(this, "确认收货\n检查商品无误后，再进行确认收货", object : PopUtils.ICallBack {
                            override fun clickOk() {
                                //确定
                                LoadingManager.showProgress(this@OrderDetailNewRetailActivity, "请稍后...")
                                viewModel.requestConfirmRecive(orderId)
                            }

                            override fun clickCancel() {
                            }
                        })
                    }
                }
            }
            R.id.tv_see_logistics, R.id.rl_logistics -> {
                //物流详情
                if (!DoubleClickHelper.isOnDoubleClick()) {
                    mDataBean.let {
                        val hashMap = java.util.HashMap<String, Any>()
                        hashMap[Constants.KEY_LOGISTICS_ORDER_NUM] = "${it?.poId}"
                        ARouterUtils.jump(ActivityRouter.NEW_RETAIL.MY_LOGISTICS, hashMap)
                    }
                }
            }
            R.id.tv_delete_order -> {
                if (!DoubleClickHelper.isOnDoubleClick()) {
                    PopUtils.showOkCancelDialog(this, "确认删除该订单？", object : PopUtils.ICallBack {
                        override fun clickOk() {
                            //删除订单
                            LoadingManager.showProgress(this@OrderDetailNewRetailActivity, "请稍后...")
                            viewModel.requestDelOrder(orderId)
                        }

                        override fun clickCancel() {}
                    }, false, "确认", "取消", true)
                }
            }
        }
    }

    private fun onlyCoinPay(poids: String) {
        //不需要支付 直接跳转 支付成功页
        viewModel.reqCreateScoreOrder(poids)
    }

    //修改地址
    private fun openChangeAddress() {
        val hashMap = HashMap<String, Any>()
        hashMap[ReceiveAddressActivity.KEY_ADDRESS_ID] = "${mDataBean?.express?.userAddressId}"
        ARouterUtils.jump(ActivityRouter.NEW_RETAIL.RECEIVE_ADDRESS, hashMap)
    }

    //待付款处理
    fun waitPayHandle() {
        mDataBean?.let {
            binding.imgTopStatus.load(this, R.drawable.ic_after_sales_details)
            binding.llCountdown.visibility = View.VISIBLE
            binding.countdownView.start(it.overtime.minus(TimeUtil.getCurrentTimeMillis()))
            binding.countdownView.setOnCountdownEndListener {
                viewModel.requestOverTimeNoPayCancel(orderId)
            }
            binding.rlLogistics.visibility = View.GONE
            //可不限制修改地址次数
            binding.imgEditChangeAddress.visibility = View.VISIBLE
            binding.imgEditChangeAddress.isSelected = true
            binding.llBottom.visibility = View.VISIBLE
            binding.tvCancelOrder.visibility = View.VISIBLE
            binding.tvPay.visibility = View.VISIBLE
        }
    }

    //待发货 可修改一次地址
    fun waitSendHandle() {
        mDataBean?.let {
            binding.imgTopStatus.load(this, R.drawable.ic_after_sales_details)
            orderBottomList.add(OrderBottomItemBean("支付时间", TimeUtil.setYearMonthDay(it.payTime), Constants.TYPE_TXT))
            //是否允许修改订单地址, 0-不允许,1-允许
            binding.imgEditChangeAddress.isSelected = it.isAllowModifyAddress == 1
            binding.rlLogistics.visibility = View.GONE
            binding.llCountdown.visibility = View.GONE
            binding.countdownView.stop()
        }
    }

    //待收货
    fun waitReceiveHandle() {
        mDataBean?.let {
            binding.imgTopStatus.load(this, R.drawable.ic_after_sales_details)
            orderBottomList.add(OrderBottomItemBean("支付时间", TimeUtil.setYearMonthDay(it.payTime), Constants.TYPE_TXT))
            orderBottomList.add(OrderBottomItemBean("发货时间", TimeUtil.setYearMonthDay(it.sendTime), Constants.TYPE_TXT))
            viewModel.reqLogisticsInfo("${it.poId}")
            binding.countdownView4Recive.visibility = if (it.receiveOvertime == 0L) View.GONE else View.VISIBLE
            binding.countdownView4Recive.start(it.receiveOvertime.minus(TimeUtil.getCurrentTimeMillis()))
            binding.countdownView4Recive.setOnCountdownEndListener {
                viewModel.requestOverTimeAutoReceive(orderId)
            }
            binding.imgEditChangeAddress.visibility = View.GONE
            binding.llBottom.visibility = View.VISIBLE
            binding.tvConfirmReceive.visibility = View.VISIBLE
        }
    }

    //已完成
    fun completeHandle() {
        mDataBean?.let {
            binding.imgTopStatus.load(this, R.drawable.ic_status_complate)
            orderBottomList.add(OrderBottomItemBean("支付时间", TimeUtil.setYearMonthDay(it.payTime), Constants.TYPE_TXT))
            if (it.sendTime != 0L) {
                orderBottomList.add(OrderBottomItemBean("发货时间", TimeUtil.setYearMonthDay(it.sendTime), Constants.TYPE_TXT))
            }
            if (it.receiveTime != 0L) {
                orderBottomList.add(OrderBottomItemBean("收货时间", TimeUtil.setYearMonthDay(it.receiveTime), Constants.TYPE_TXT))
            }
            viewModel.reqLogisticsInfo("${it.poId}")
            binding.imgEditChangeAddress.visibility = View.GONE
        }
    }

    //已关闭
    fun closeHandle() {
        mDataBean?.let {
            binding.imgTopStatus.load(this, R.drawable.ic_order_status_close)
            orderBottomList.add(OrderBottomItemBean("取消时间", TimeUtil.setYearMonthDay(it.cancelTime), Constants.TYPE_TXT))
            if (it.cancelType == 2) {
                orderBottomList.add(OrderBottomItemBean("取消原因", if (it.orderCancelReason.checkNotNull()) it.orderCancelReason.desc.checkValue() else "", Constants.TYPE_TXT))
            } else {
                orderBottomList.add(OrderBottomItemBean("取消原因", OptionUtils.cancelType(it.cancelType), Constants.TYPE_TXT))
            }
            binding.imgEditChangeAddress.visibility = View.GONE
            binding.llCountdown.visibility = View.GONE
            binding.llBottom.visibility = View.VISIBLE
            binding.tvDeleteOrder.visibility = View.VISIBLE
        }
    }

    //取消订单弹窗
    private fun cancelOrderHandle(reasonList: List<CancelReasonListBean>) {
        RetailPopUtils.showCancelOrderDialog(this, reasonList, object : RetailPopUtils.ICallBack4CancelOrderSelectReson {
            override fun onClickOk(isRebackCart: Boolean, cancellationId: Int) {
                viewModel.reqCancelOrder("${mDataBean?.poId}", cancellationId, if (isRebackCart) 1 else 0)
            }
        })
    }

    private fun setAddressInfo(name: String, phone: String, detail: String) {
        binding.tvNamePhone.text = "${name} ${phone}"
        binding.tvProvinceCityDetail.text = "${detail}"
    }

    //EventBus 接受方法
    @Subscribe(threadMode = ThreadMode.MAIN) fun onEvent(messageBus: MessageBus) {
        if (messageBus.codeType == MessageBus.msgId_select_address_complete) {
            //选择地址
            val selectAddressBean = messageBus.message as ReceiveAddressBean
            selectAddressBean.let {
                setAddressInfo(it.name, it.phone, "${CommonUtil.jsonToBean(it.areaFirst, AddressData::class.java).name.checkValue()}${CommonUtil.jsonToBean(it.areaSecond, AddressData::class.java).name.checkValue()}${CommonUtil.jsonToBean(it.areaThree, AddressData::class.java).name.checkValue()}${it.address}")
                if (mDataBean?.express?.userAddressId != it.id) {//如果用户在收货地址列表选择的是当前地址，则直接返回上一级页面，不计算修改次数
                    mDataBean?.express?.userAddressId = it.id//用于记录使用中
                    LoadingManager.showProgress(this@OrderDetailNewRetailActivity, "请稍后...")
                    viewModel.reqChangeReciveAddress("${mDataBean?.poId}", it.id)
                }
            }
        } else if (messageBus.codeType == MessageBus.msgId_retail_after_sales_revoke || messageBus.codeType == MessageBus.msgId_after_sale_apply_success || messageBus.codeType == MessageBus.msgId_retail_after_sales_re_apply_success || messageBus.codeType == MessageBus.msgId_pay_success) {
            //撤销售后/申请售后成功/售后重新申请 支付成功 刷新订单
            reqData()
        }
    }

    override fun onResume() {
        super.onResume()
        reqData()
    }

    override fun onDestroy() {
        mDataBean?.status?.let { EventBusUtils.sendNotify1Value(MessageBus.msgId_close_order_detail, it) }
        if (EventBus.getDefault().isRegistered(this)) {
            EventBus.getDefault().unregister(this)
        }
        super.onDestroy()
    }
}